import 'dart:convert';
import 'dart:math';
import 'dart:typed_data';
import 'package:flutter_test/flutter_test.dart';
import 'package:hex/hex.dart';
import 'package:eciesdart/src/bigint.dart';
import 'package:pointycastle/export.dart';
import 'package:bip39/bip39.dart' as bip39;
import 'package:xim/common/util/secp256.dart';

void main(){
  var mnemonic = Secp256R1Util.generateMnemonic();
  // var seed = Secp256R1Util.mnemonicToSeed(mnemonic);
  var seed = [73, 236, 57, 39, 146, 163, 54, 167, 207, 1, 178, 183, 100, 153, 37, 47, 254, 106, 66, 189, 49, 189, 102, 106, 93, 1, 224, 49, 165, 193, 155, 90, 19, 77, 131, 180, 10, 116, 224, 210, 98, 38, 201, 147, 140, 113, 36, 69, 97, 72, 17, 31, 89, 150, 209, 147, 218, 89, 117, 130, 214, 198, 71, 133];
  print("seed:$seed");
  var privateKey = Secp256R1Util.generateEcPrivateKey(Uint8List.fromList(seed));
  var publicKey = Secp256R1Util.generateEcPublicKey(privateKey);

  var string = publicKey.Q.toString();
  print(string);
  print(publicKey.hexKey());

  var plainText = "awdawdada";
  var plainEncode = utf8.encode(plainText);
  var encodeMsg = Secp256R1Util.encrypt2(publicKey, plainEncode);
  print(base64.encode(encodeMsg));

  var a = "BIF/I0wz2NTZ+A3qTjJ5jv3vVQY9wWXxT28CoZ/4IUTVS5290aZvOLoO+N9rDTwrdgmlpAH8mA4vniHeVUCJP296poy2RXOVdfGU8+Nz0J07IXyrcd7iLPchuslYXw==";
  var decode = base64.decode(a);
  Secp256R1Util.decrypt2(privateKey, decode);

  // var res = decrypt2(privateKey, encodeMsg);
}
